<!--
 * @Descripttion:菜品分类报表
 * @Author: 森哥
 * @Date: 2022-11-08 14:42:46
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2024-11-04 21:18:19
-->
<template>
  <div>
    <div class="food-category-card-box">
      <!-- 骨架屏 -->
      <div v-if="loading" class="skeleton-container">
        <!-- 标题骨架 -->
        <div class="skeleton-title"></div>
        <div class="skeleton-description"></div>
        <div class="skeleton-time"></div>

        <!-- 内容骨架 -->
        <div v-for="i in 3" :key="i" class="skeleton-content">
          <div class="skeleton-section-title"></div>
          <div class="skeleton-table">
            <div class="skeleton-header">
              <div class="skeleton-cell"></div>
              <div class="skeleton-cell"></div>
              <div class="skeleton-cell"></div>
              <div class="skeleton-cell"></div>
            </div>
            <div v-for="j in 4" :key="j" class="skeleton-row">
              <div class="skeleton-cell"></div>
              <div class="skeleton-cell"></div>
              <div class="skeleton-cell"></div>
              <div class="skeleton-cell"></div>
            </div>
          </div>
        </div>

        <!-- 合计骨架 -->
        <div class="skeleton-summary"></div>
      </div>

      <!-- 实际内容 -->
      <div v-else>
        <!-- 餐厅名字 -->
        <div class="title">{{ dishesList.shopName }}</div>
        <div class="description">【部门营业报表】</div>
        <!--  营业时间 -->
        <div class="business-time">营业时间：{{ dishesList.time_block }}</div>
        <!-- 菜品分类循环的大盒子 -->
        <div
          v-if="dishesList.list && dishesList.list.length > 0"
          v-for="(v, i) in dishesList.list"
          :key="i"
        >
          <div class="business-time" style="margin-bottom: 0px">桌台区域：{{ v.name }}</div>

          <div class="dishes-category-list-box" v-for="(item, index) in v.list" :key="index">
            <!-- 主食 -->
            <div class="staple-food">{{ item.name }}</div>
            <!-- 表头 -->
            <div class="dishes-category-header">
              <div class="dishes-name-title">菜品名称</div>
              <span class="dishes-num-title">数量</span>
              <span class="dishes-price-title">单价</span>
              <div class="dishes-total-title">总金额</div>
            </div>
            <div class="desc-line"></div>
            <!-- 菜品参数 -->
            <div
              class="desc-list-box"
              v-for="(dishes, dishesIndex) in item.list"
              :key="dishesIndex"
            >
              <div class="desc-list-item">
                <div class="dishes-name">{{ dishes.name }}</div>
                <span class="dishes-num">{{ dishes.num }}份</span>
                <div class="dishes-price">&yen;{{ dishes.money }}</div>
                <div class="dishes-total">&yen;{{ dishes.total_money }}</div>
              </div>
              <div class="desc-line"></div>
            </div>
            <!-- 合计 -->
            <div class="desc-summary-item">
              <div class="dishes-summary-name">{{ item.name }}合计：</div>
              <span class="dishes-summary-num">{{ totalCount(item.list) }}份</span>
              <div class="dishes-summary-price"></div>
              <div class="dishes-summary-total">&yen;{{ totalMoney(item.list) }}</div>
            </div>
          </div>
        </div>
        <!-- 所有菜品金额的合计 -->
        <div v-if="dishesList.list && dishesList.list.length > 0" class="dishes-summary-box">
          <div>合计</div>
          <div>&yen;{{ totalDishesMoney }}</div>
        </div>
        <div v-else class="no-data">暂无数据</div>
        <!-- 餐厅地址 -->
        <div class="address-phone-box">
          <div>餐厅地址：贵阳市南明区中华南路52号钻石广场3006</div>
          <div>餐厅电话：400-0851-123</div>
          <div>技术支持：贵州一粒米科技餐饮软件服务有限公司</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue'

// 菜品分类列表
const props = defineProps({
  dishesList: {
    type: Object,
    default: {}
  },
  loading: {
    type: Boolean,
    default: false
  }
})

// 菜品分类数量合计
const totalCount = arr => {
  let count = 0
  arr.map(v => (count += Number(v.num)))
  return count
}

// 菜品分类总金额合计
const totalMoney = arr => {
  let count = 0
  arr.map(v => (count += v.total_money))
  return count
}

// 所有菜品金额总计
const totalDishesMoney = computed(() => {
  let count = 0
  const arr = props.dishesList.list
  if (!arr) return count
  arr.map(v => {
    Object.keys(v.list).map(k => {
      v.list[k].list.map(res => {
        count += res.total_money
      })
    })
    return v
  })
  return count.toFixed(2)
})
</script>

<style lang="scss" scoped>
.food-category-card-box {
  width: 420px;
  height: 986px;
  background: #ffffff;
  border-radius: 20px;
  box-shadow: 3px 0px 24px 0px rgba(0, 0, 0, 0.16);
  box-sizing: border-box;
  padding: 30px;
  overflow-y: scroll;
  .title {
    font-size: 20px;
    font-family:
      PingFang SC,
      PingFang SC-Bold;
    font-weight: 700;
    text-align: center;
    color: #333333;
  }
  .business-time {
    margin-top: 20px;
    font-size: 14px;
    font-family:
      PingFang SC,
      PingFang SC-Bold;
    font-weight: 700;
    text-align: left;
    color: #333333;
    margin-bottom: 20px;
  }

  .description {
    font-size: 16px;
    font-family:
      PingFang SC,
      PingFang SC-Bold;
    font-weight: 700;
    text-align: center;
    color: #333333;
    margin: 10px 0;
  }
  .dishes-category-list-box {
    margin-bottom: 42px;
    .staple-food {
      font-size: 16px;
      font-family:
        PingFang SC,
        PingFang SC-Bold;
      font-weight: 700;
      text-align: center;
      color: #333333;
      margin-bottom: 20px;
    }
    .dishes-category-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-top: 11px;
      font-size: 14px;
      font-family:
        PingFang SC,
        PingFang SC-Bold;
      font-weight: 700;
      color: #333333;
      .dishes-name-title {
        width: 25%;
        display: flex;
        justify-content: flex-start;
      }
      .dishes-num-title {
        width: 25%;
        display: flex;
        justify-content: center;
      }
      .dishes-price-title {
        width: 25%;
        display: flex;
        justify-content: flex-end;
      }
      .dishes-total-title {
        width: 25%;
        display: flex;
        justify-content: flex-end;
      }
    }
    .desc-list-box {
      display: flex;
      flex-direction: column;
      .desc-list-item {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-top: 11px;
        font-size: 14px;
        font-family:
          PingFang SC,
          PingFang SC-Bold;
        font-weight: 700;
        color: #333333;
        .dishes-name {
          width: 25%;
          display: flex;
          justify-content: flex-start;
        }
        .dishes-num {
          width: 25%;
          display: flex;
          justify-content: center;
        }
        .dishes-price {
          width: 25%;
          display: flex;
          justify-content: flex-end;
        }
        .dishes-total {
          width: 25%;
          display: flex;
          justify-content: flex-end;
        }
      }
      .desc-line {
        width: 360px;
        height: 1px;
        background: #e2e2e2;
        margin-top: 10px;
      }
    }

    .desc-summary-item {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-top: 11px;
      font-size: 14px;
      font-family:
        PingFang SC,
        PingFang SC-Bold;
      font-weight: 700;
      color: #333333;
      .dishes-summary-name {
        width: 25%;
        display: flex;
        justify-content: flex-start;
      }
      .dishes-summary-num {
        width: 25%;
        display: flex;
        justify-content: center;
      }
      .dishes-summary-price {
        width: 25%;
        display: flex;
        justify-content: flex-end;
      }
      .dishes-summary-total {
        width: 25%;
        display: flex;
        justify-content: flex-end;
      }
    }
  }
  .dishes-summary-box {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    font-family:
      PingFang SC,
      PingFang SC-Bold;
    font-weight: 700;
    color: #333333;
    align-items: center;
    // margin-top: -20px;
  }
  .desc-line {
    width: 360px;
    height: 1px;
    background: #e2e2e2;
    margin-top: 10px;
  }
  .desc-title {
    font-size: 16px;
    font-family:
      PingFang SC,
      PingFang SC-Bold;
    font-weight: 700;
    text-align: center;
    color: #333333;
    margin: 20px 0 10px 0;
  }
  .no-data {
    text-align: center;
    padding: 20px;
    color: #999;
  }

  .address-phone-box {
    margin-top: 50px;
    font-size: 14px;
    font-family:
      PingFang SC,
      PingFang SC-Regular;
    font-weight: 400;
    text-align: center;
    color: #333333;
    line-height: 24px;
    > div {
      margin-bottom: 10px;
    }
  }
}
//滚动条整体的大小
.food-category-card-box::-webkit-scrollbar {
  width: 6px !important;
  height: 0 !important;
}
//滚动条里滑动的滑块
.food-category-card-box::-webkit-scrollbar-thumb {
  height: 200px !important;
  background: #d2d2d2 !important;
  border-radius: 3px !important;
}
//滚动条底层样式
.food-category-card-box::-webkit-scrollbar-track {
  display: none !important;
}

// 骨架屏样式
.skeleton-container {
  .skeleton-title {
    height: 24px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
    margin-bottom: 10px;
    width: 60%;
    margin: 0 auto 10px;
  }

  .skeleton-description {
    height: 20px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
    margin-bottom: 20px;
    width: 40%;
    margin: 0 auto 20px;
  }

  .skeleton-time {
    height: 18px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
    margin-bottom: 20px;
    width: 50%;
  }

  .skeleton-content {
    margin-bottom: 30px;

    .skeleton-section-title {
      height: 20px;
      background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
      background-size: 200% 100%;
      animation: skeleton-loading 1.5s infinite;
      border-radius: 4px;
      margin-bottom: 15px;
      width: 30%;
    }

    .skeleton-table {
      .skeleton-header {
        display: flex;
        justify-content: space-between;
        margin-bottom: 10px;

        .skeleton-cell {
          height: 16px;
          background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
          background-size: 200% 100%;
          animation: skeleton-loading 1.5s infinite;
          border-radius: 4px;
          width: 22%;
        }
      }

      .skeleton-row {
        display: flex;
        justify-content: space-between;
        margin-bottom: 8px;

        .skeleton-cell {
          height: 14px;
          background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
          background-size: 200% 100%;
          animation: skeleton-loading 1.5s infinite;
          border-radius: 4px;
          width: 22%;
        }
      }
    }
  }

  .skeleton-summary {
    height: 20px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
    margin: 20px 0;
    width: 40%;
  }
}

@keyframes skeleton-loading {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}
</style>
